//
//  MovieCollectionViewController.m
//  豆瓣终极版
//
//  Created by dllo on 15/12/19.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "MovieCollectionViewController.h"
#import "MyCollectionViewCell.h"
#import "Movie.h"
#import "MovieDetailViewController.h"
#import "AppTools.h"
#import "MovieDetail.h"
@interface MovieCollectionViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation MovieCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(112, 150);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    flowLayout.minimumLineSpacing = 70;
    flowLayout.minimumInteritemSpacing = 1;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    UICollectionView *myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 375, 667 - 140) collectionViewLayout:flowLayout];
    myCollectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:myCollectionView];
    myCollectionView.delegate = self;
    myCollectionView.dataSource = self;
    
    [myCollectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_list@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(collectButtonAction:)];
    

    }

- (void)collectButtonAction:(UIBarButtonItem *)btn{
    [self.navigationController popViewControllerAnimated:NO];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    Movie *movie = [self.array objectAtIndex:indexPath.row];
    cell.movie = movie;
    cell.backgroundColor = [UIColor lightGrayColor];
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    MovieDetailViewController *movieDetailVC = [[MovieDetailViewController alloc] init];
    
    Movie *movie = [self.array objectAtIndex:indexPath.row];
    
    movieDetailVC.movieId = movie.movieId;
    
    
    [self.navigationController pushViewController:movieDetailVC animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
